<?php

class backend_model_ extends jqxGrid_CI_Model {

    protected $mytable,$_id;
    function __construct($mytable="")
    {
        parent::__construct();
        $this->mytable=$mytable;
        $this->_id="_id";
        if($mytable=="dtb_product")
            $this->_id="ProductID"; 
        if($mytable=="dtb_orders")
            $this->_id="OrderID"; 
        if($mytable=="_type")
            $this->_id="_id"; 
    }
    function toString(){
        echo $this->mytable;
    }
    function get($_id=""){
        $where=array($this->_id=>$_id);
        $query=$this->db->get_where($this->mytable, $where); 
        return $query->result();
    }
    function insert($Params){
        $this->db
            ->insert($this->mytable, $Params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($_id,$Params){
        if(is_array($_id)){
            $this->db->where_in($this->_id, $_id);
        }else{
            $this->db->where($this->_id, $_id);
        }
        $this->db->update($this->mytable, $Params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count>0) return $count;
        return false;
    }
    function updateColumn($_id,$col,$val){
        if(is_array($_id)){
            $this->db->where_in($this->_id, $_id);
        }else{
            $this->db->where($this->_id, $_id);
        }
        $Params[$col]=$val;
        $this->db->update($this->mytable, $Params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count>0) return $count;
        return false;
    }
    
}
?>
